﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AdinZ.Common;
using Novel.Sys;
/**
* @Author: AdinZ
* @Q  Q : 1454269
* @Email:adinz@adinz.com
* @Created: 2014/3/31 18:02:58
* */
namespace Web.admin
{
    public partial class Default : AdinZ.Web.UI.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            string vAct = Request.QueryString["action"] != null ? Request.QueryString["action"] : "";
            if (vAct == "loginout")
            {
                //清除cookie
                Novel.Utils.CookieUtil.DelCookie(Novel.Utils.CookieUtil.GetAdminGid());
                Response.Redirect(this.Request.Path);
            }
            string JC_UserName = Novel.Utils.CookieUtil.GetAdminName();
            string JC_PassWord = Novel.Utils.CookieUtil.GetAdminPasswd();

            if (!string.IsNullOrEmpty(JC_UserName))
            {
                if (bll_user.Exists(JC_UserName.Trim(), JC_PassWord.Trim()))
                {
                    model_user = bll_user.GetModel(JC_UserName);
                    if (model_user.Gid == 10)
                    {
                        Response.Redirect("Main.aspx");
                    }else
                        MessageBox.Show(this, "用户名或密码错误");

                }
            }

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (this.tbName.Text.Trim().Length == 0)
            {
                MessageBox.Show(this, "请输入用户名!");
                return;
            }
            if (this.tbPasswd.Text.Trim().Length == 0)
            {
                MessageBox.Show(this, "请输入密码!");
                return;
            }
            string name = tbName.Text.Trim();
            string passwd = EncryAndDecry.EncryMd5(tbPasswd.Text.Trim(),true,true);

            if (!bll_user.Exists(name.Trim(), passwd.Trim())) { MessageBox.Show(this, "用户名不存在"); return; }
            else {
                model_user = bll_user.GetModel(name.Trim());
                if (model_user.Gid == 10)
                {
                    Novel.Utils.CookieUtil.SaveCookie(model_user, 10080);
                    Response.Redirect("Main.aspx");
                }
                else
                    MessageBox.Show(this, "用户名或密码错误");
            }
           
        }
    }
}